<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <ul>
    <li>西游记</li>
    <li>水浒传</li>
    <li>三国演义</li>
    <li>红楼梦</li>
  </ul>
  <!-- 原始方法 直接获取到标签 -->
  <script>
    var lis = document.querySelectorAll('li');
    console.log(lis);
    for(var i = 0; i < lis.length; i++){
      if(i % 2 == 0){
        lis[i].style.backgroundColor = 'red';
      }else{
        lis[i].style.backgroundColor = 'pink';
      }
    }
  </script>
  <!-- 采用节点方法 使得子节点变色 -->
  <script>
    var ul = document.querySelector('ul');
    if(ul.children.length > 0 ){
      var lis = ul.children;
      for(var i = 0; i < lis.length; i++){
        if(i % 2 == 0 ){
          lis[i].style.backgroundColor = 'red';
        }else{
          lis[i].style.backgroundColor = 'pink';
        }
      }
    }
  </script>

</body>
</html>